<template>
  <!-- 秒杀 -->
  <div class="hot">
    <p class="text">
      京东秒杀 
      <span class="hour">14</span>
      <img src="https://wq.360buyimg.com/jdm-home-page/pages/images/seckill-time-to_1de70c91.png">
      <van-count-down :time="time" @finish="timeoverHandler">
        <template #default="timeData">
          <span class="block">{{ timeData.hours }}</span>
          <span class="colon">:</span>
          <span class="block">{{ timeData.minutes }}</span>
          <span class="colon">:</span>
          <span class="block">{{ timeData.seconds }}</span>
        </template>
    </van-count-down>
     
    </p>

    <div class="bottom">
      <ul>
        <li v-for="item in hotList" :key="item.proid">
          <img :src="item.img1">
          <p>{{ item.category }}</p>
        </li>
      </ul>
    </div>
  </div>
</template>
<script setup lang="ts">
import { showToast } from 'vant'
import { getHotList } from '../../../request/home.ts'
import { ref, onMounted } from 'vue'

const hotList = ref<Array<HotData>>([])
// 时间差
const targetTime = new Date(' 2023/7/5 14:00:00 ')
const time = targetTime.getTime() - new Date().getTime()

// 秒杀结局的回调函数
const timeoverHandler = () => {
  showToast({
  message: '秒杀结束',
  icon: 'like-o'
  })
}
// 热门商品data接口
interface HotData {
  img1?: string,
  proid?: string,
  category: string,
  [key: string]: any
}
// 请求回来的数据接口
interface Reponse {
  code?: string,
  data?: Array<HotData>
}

onMounted(async () => {
  const res = await getHotList()
  if ((res as Reponse).code !== '200') return

  hotList.value = res.data
})
</script>
<style scoped lang="scss">

.hot{
  width: 95%;
  background-color: #fff;
  border-radius: 5px;
  margin: 0 auto;
  .text{
    margin: 10px 15px;
    position: relative;
    overflow: hidden;
    font-size: 20px;
    background-image: url();
    background-size: 100%;
    background-repeat: no-repeat;
    >.hour{
      color: #ff0000;
      margin-left: 5px;
      margin-right: 5px;
    }
    img{
      width: 30px;
      position: absolute;
      top: 3px;
    }
  }

  .bottom{
    overflow: auto;
    flex: 1;
    padding: 10px;
    padding-top: 0;
    box-sizing: border-box;
    ul{
      display: flex;
      li{
        margin-right: 10px;
        display: flex;
        flex-direction: column;
        align-items: center;
        img{
          width: 70px;
          height: 70px;
          display: block;
        }
        span{
          font-size: 12px;
        }
      }
    }
  }
}
.colon {
    display: inline-block;
    margin: 0 4px;
    color: #ff0000;
  }
  .block {
    display: inline-block;
    width: 22px;
    color: #fff;
    font-size: 12px;
    text-align: center;
    background-color: #ff0000;
  }
  .block[data-v-e726c891]{
    border-radius: 4px;
  }
  .colon[data-v-e726c891]{
    font-weight: 600;
  }
  .van-count-down{
    display:inline-block;
    margin-left: 50px;
  }
</style>
